package com.example.smartcity_ikun3.ui.Smart.adapter

import android.content.Intent
import android.text.Layout
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.smartcity_ikun3.R
import com.example.smartcity_ikun3.logic.util.Util.show
import com.example.smartcity_ikun3.ui.Smart.model.SmartMoreEntity
import com.example.smartcity_ikun3.ui.Smart.view.SmartMoreFourActivity
import com.example.smartcity_ikun3.ui.Smart.view.SmartMoreOne
import com.example.smartcity_ikun3.ui.Smart.view.SmartMoreThreeActivity
import com.example.smartcity_ikun3.ui.Smart.view.SmartMoreTwoActivity

class SmartMoreRecyclerViewAdapter (
    val data: List<SmartMoreEntity>
) : RecyclerView.Adapter<SmartMoreRecyclerViewAdapter.ViewHolderView>(){
    inner class ViewHolderView(view: View) : RecyclerView.ViewHolder(view){
        val setImg = view.findViewById(R.id.homeMoreImageView) as ImageView
        val setTv = view.findViewById(R.id.homeMoreTitle) as TextView
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderView {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.re_home_more, parent, false)
        val view = ViewHolderView(root)

        view.itemView.setOnClickListener {
            if (view.setTv.text == "健康评估") parent.context.startActivity(Intent(parent.context, SmartMoreOne::class.java))

            if (view.setTv.text == "监测") parent.context.startActivity(Intent(parent.context, SmartMoreTwoActivity::class.java))

            if (view.setTv.text == "服务巡检") parent.context.startActivity(Intent(parent.context, SmartMoreThreeActivity::class.java))

            if (view.setTv.text == "集中监测") parent.context.startActivity(Intent(parent.context, SmartMoreFourActivity::class.java))
        }

        return view
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: ViewHolderView, position: Int) {
        val list = data[position]
        holder.setImg.setImageResource(list.imageView)
        holder.setTv.text = list.Title
    }
}